/**
 * @file shell_task.c
 * @brief shell交互任务程序
 * @author wangh (wanghuan3037@fiberhome.com)
 * @version 1.0
 * @date 2020-11-17
 * @copyright Copyright (c) 2020  烽火通信
 ***************************************************************
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version  <th>Author  <th>Description
 * <tr><td>2020-11-17 <td>1.0      <td>wangh   <td>内容
 * </table>
 */ 
#include "project_config.h"

#if SHELL_TASK_EN
#include "FreeRTOS.h"
#include "task.h"
#include <string.h>
#include "nr_micro_shell.h"
#include "nrf_log.h"

#define RTT_BUF_SIZE	50
static uint8_t rtt_buf[RTT_BUF_SIZE];

/**
 * @brief shell接收任务
 */
void shell_task(void *para)
{
    NRF_LOG_INFO("shell_task start...\r\n");

    shell_init();

    while(1)
    {
        uint8_t rtt_len = SEGGER_RTT_Read(0, rtt_buf, RTT_BUF_SIZE);
        if(rtt_len > 0)
        {
            uint8_t i;
            for(i=0; i<rtt_len; i++)
                shell(rtt_buf[i]);	/* nr_micro_shell接收字符 */
        }

        vTaskDelay(1);
    }
}


/**
 * @brief ls command
 * @param  argc     	命令参数个数
 * @param  argv        	命令参数数组指针
 */
static void shell_ls_cmd(char argc, char *argv)
{
    unsigned int i = 0;
    if (argc > 1)
    {
        if (!strcmp("cmd", &argv[argv[1]]))
        {

            for (i = 0; nr_shell.static_cmd[i].fp != NULL; i++)
            {
                shell_printf(nr_shell.static_cmd[i].cmd);
                shell_printf("\r\n");
            }
        }
        else if (!strcmp("-v", &argv[argv[1]]))
        {
            shell_printf("ls version 1.0.\r\n");
        }
        else if (!strcmp("-h", &argv[argv[1]]))
        {
            shell_printf("useage: ls [options]\r\n");
            shell_printf("options: \r\n");
            shell_printf("\t -h \t: show help\r\n");
            shell_printf("\t -v \t: show version\r\n");
            shell_printf("\t cmd \t: show all commands\r\n");
        }
    }
    else
    {
        shell_printf("ls need more arguments!\r\n");
    }
}

#ifdef NR_SHELL_USING_EXPORT_CMD
NR_SHELL_CMD_EXPORT(ls, shell_ls_cmd);
#endif



#endif  /* SHELL_TASK_EN */
/*********** (C) COPYRIGHT 2020 FiberHome *****END OF FILE****/
